package com.ursu.client.presenter;

import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.ProxyEvent;
import com.gwtplatform.mvp.client.annotations.ProxyStandard;
import com.gwtplatform.mvp.client.annotations.NameToken;
import com.ursu.client.event.LoginAuthenticatedEvent;
import com.ursu.client.event.LoginAuthenticatedEvent.LoginAuthenticatedHandler;
import com.ursu.client.place.NameTokens;
import com.gwtplatform.mvp.client.annotations.UseGatekeeper;
import com.ursu.client.AdminGatekeeper;
import com.gwtplatform.mvp.client.proxy.ProxyPlace;
import com.google.inject.Inject;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextBox;
import com.gwtplatform.mvp.client.proxy.RevealRootContentEvent;

public class CreateAdminPresenter extends
		Presenter<CreateAdminPresenter.MyView, CreateAdminPresenter.MyProxy> implements LoginAuthenticatedHandler {

	private String username;
	
	public interface MyView extends View {
		public Button getLogoutBtn();
		public Button getCreateAdminBtn();
    	public TextBox getUsernameBox();
        public PasswordTextBox getPasswordBox();
        public PasswordTextBox getConfPasswordBox();
		
	}

	@ProxyStandard
	@NameToken(NameTokens.createadmin)
	@UseGatekeeper(AdminGatekeeper.class)
	public interface MyProxy extends ProxyPlace<CreateAdminPresenter> {
	}

	@Inject
	public CreateAdminPresenter(final EventBus eventBus, final MyView view,
			final MyProxy proxy) {
		super(eventBus, view, proxy);
	}

	@Override
	protected void revealInParent() {
		RevealRootContentEvent.fire(this, this);
	}

	@Override
	protected void onBind() {
		super.onBind();
	}

	@Override
	protected void onReset() {
		super.onReset();
		getView().getLogoutBtn().setText("Logout "+username);
	}

	@ProxyEvent
	@Override
	public void onLoginAuthenticated(LoginAuthenticatedEvent event) {
		if(event.getCurrentUser() !=  null)
		username = event.getCurrentUser().getUsername();
		
	}
}
